package com.lb.activity.sys.controller;

import com.lb.activity.po.Role;
import com.lb.activity.sys.service.RoleService;
import com.lb.activity.util.ResultUtil;
import com.lb.activity.vo.PageVo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

/**
 * @author 001030
 */
@RestController
public class RoleController {

    @Resource
    private RoleService roleService;


    @GetMapping("role")
    public ModelAndView role(){
        return new ModelAndView("role/role");
    }

    @GetMapping("toRoleAdd")
    public ModelAndView toRoleAdd(){
        return new ModelAndView("role/role-add");
    }

    @PostMapping("roleAdd")
    public Object roleAdd(Role role){
        ResultUtil resultUtil = roleService.addRole(role);
        return resultUtil;
    }

    @GetMapping("roles")
    public Object roles(PageVo pageVo){
        ResultUtil resultUtil = roleService.roles(pageVo);
        return resultUtil;
    }

    @GetMapping("assignRole")
    public ModelAndView assignRole( Long id){
        //查询role信息，反显
        Role role = roleService.getRoleById(id);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("role",role);
        modelAndView.setViewName("role/assignRole");
        return modelAndView;
    }

}
